<?php include COMMON_PATH.'/index/header.html' ?>
<!--论坛发帖发布-->
<div class="se-wrap main-content fl-wrap fs-wrap clearfix">
    <div class="fl left-box">
        <div class="title">我的论坛</div>
        <ul class="user-result-wrap">
            <li class="first">
                <img class="avatar" src="<?=$user['avatar']?>" alt="" onerror="iService.imgNoFind(this);">
                <p><span class="am-icon-venus"></span>&nbsp;<?=$user['nickname']?>&nbsp;<?=$user['section']?></p>
            </li>
            <li class="last">
                <i class="am-icon-file-text"></i><span class="justify" style="font-size: 16px;">我的文章</span>：<b><?=$myPosts['count']?></b>
                <ol>
                    <?php foreach($myPosts['lists'] as$k=>$v):?>
                    <li><a class="btn-font-all" href="/Society/detail?sid=<?=$v['sid']?>"><?=$k+1?>、<?=$v['title']?></a></li>
                    <?php endforeach;?>
                </ol>
            </li>
        </ul>
    </div>
    <div class="fr right-box">
        <div class="title">
            <b class="fl">发帖</b>
            <a class="fr btn-forum-send" href="javascript:void(0);">发布</a>
        </div>
        <form class="fs-send-wrap" action="">
            <div class="pic-upload-wrap clearfix">
                <div class="fl pic-wrap btn-upload">
                    <i class="layui-icon">&#xe660;</i>
                    <input id="uploadBtn" type="file" accept="image/jpg,image/jpeg,image/png" name=img />
                </div>
            </div>
            <div class="input-wrap" id="forum-text-title">
                <input type="text" name="title" placeholder="请输入标题" />
            </div>

            <div class="textarea-wrap" id="forum-text-content">
                <textarea name="" placeholder="编辑内容"></textarea>
            </div>
            <div id="fs-send-tool">
                <span class="submit">发布</span>
                <span class="reset">放弃</span>
            </div>
        </form>
    </div>
</div>

<?php include COMMON_PATH.'/index/footer.html' ?>
<script type="text/javascript" src="/index/js/autosize.js"></script>
<script>
    navActive(4);
    $(function(){
        $('#forum-text-content textarea').autosize();
    }); ``

layui.use(['element','layer','form', 'laypage', 'laydate'], function() {

    var url_pic = '<?=$imgPath?>';

    $('.pic-upload-wrap').on('click', '.icon-close', function () {
        $(this).parents('.pic-wrap').remove();
    });

    $('#uploadBtn').on('change', function () {
        var file_form = new FormData($('.fs-send-wrap')[0]);//提交表单所有数据
        $.ajax({
            type: "post",
            url: "/about/upload",
            data: file_form,
            processData: false,
            contentType: false,
            async: true,
            datatype: "JSON",
            success: function (obj) {
                var data = $.parseJSON(obj);
                if (data.code = !200) {
                    layer.msg(data.data.message, {icon: 1,anim: 6,time:2*1000});
                } else {
                    $('div.btn-upload').before(
                            '<div class="fl pic-wrap" data-file="' + data.data.file + '"  data-path="' + data.data.path + '">' +
                            '<img src="' + url_pic + data.data.path + data.data.file + '" alt="">' +
                            '<i class="layui-icon icon-close">ဇ</i>' +
                            '</div>'
                    )
                }
                $('.fs-send-wrap')[0].reset();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest.readyState);
            }
        });
    });



    $('#fs-send-tool .submit').on('click',function(){

        var title = $('input[name=title]').val(),
            content = $('#forum-text-content textarea').val(),
            path = '',
            file = '';

        if($('.pic-wrap').not('.btn-upload')){
            $.each($('.pic-wrap').not('.btn-upload'),function(){
                path += $(this).attr('data-path')+',';
                file += $(this).attr('data-file')+',';
            });
        }
        path = path.slice(0,path.length-1);
        file = file.slice(0,file.length-1);
        var param = {
            url: 'society/sendPost',
            data:{
                title: title,
                content: content,
                path: path,
                file: file
            }
        };
        $.JsonRpc(param,successFun);
        function successFun(data){
            console.log(data);
            if (data.code !=200) {
                layer.msg(data.data.message, {icon: 1,anim: 6,time:2*1000});
            } else {
                layer.msg(data.data.message,{anim:0,time:1500,end:function(){
                    window.location.href = '/society/index';
                }});
            }
        }
    });

    $('#fs-send-tool .reset').on('click',function(){
        layer.confirm('确定将清除所有内容', {icon: 3, title:'提示'}, function(){
            layer.closeAll();
            $('.pic-wrap').not('.btn-upload').remove();
            $('.fs-send-wrap')[0].reset();
        }, function(){
//            取消
        })
    });

});


</script>
</html>







